$(function(){
	//ajax全局设置
	var getRecordId,getSsid,getForward,specialAddPart,partSelectId="",partSelectText=""; 
	$.ajaxSetup({
		timeout:30000,
		beforeSend: function(request) {
            request.setRequestHeader("X-AIRPORT-TOKEN", localStorage.getItem("oauth_token"));
        },
        error:function(xhr,status){
			layer.msg("网络连接已超时，请重新刷新！");
		}
	})
	
	/*$("input[name='iCheck']").iCheck({
	    checkboxClass: 'icheckbox_square',
	    radioClass: 'iradio_square',
	    increaseArea: '20%' // optional
	 });*/
	//页面获取数据
	var getURL=window.location.search;
	if(getURL.indexOf("hideCheck=0")!=-1){
		$(".specialAddNav>div:eq(1)").hide();
	}
	var specialReceiveInfo=function(){
		var loadIndex=layer.load("正在努力加载中，请稍候!");
		$.ajax({
		type:'get',
		url:baseURL+"/api/special/getSpecialInfoByIdForWeb"+getURL+"&refever="+Math.random(),
		dataType:'json',
		contentType:"application/json",
		success:function(result){
			layer.close(loadIndex);
			if(!result.flag){
				layer.msg("数据错误:"+result.message);
			}else{
				var obj=result.result;
				var html="";
				html+="<div class='col-offset-1 col-10'><div class='spicailItemLine mt-10'><h5 class='f-l col-8 f-14' style='font-weight:bold'>"+obj.topic+"</h5><div class='f-l text-l mt-10'>"+changeLevelColor(obj.level)+"</div></div><div class='col-12'><span class='col-12 mt-5 c-999 spicailItemzCon'>"+obj.contents+"</span></div><div class='col-12'><span class='c-555 col-12 mt-10'>"+getTime(obj.publishTime)+"</span></div><div class='col-12'><div class='width60px f-l c-999 mt-10'>特情来源</div><ul class='f-l spicailItemResouse_1'>"
				if(obj.status=="0"){
			  		 html+="<li class='spicailItemred'>"+obj.publishOrg+"</li>"
			  	 }else if(obj.status=="1"){
			  		 html+="<li class='spicailItemYellow'>"+obj.publishOrg+"</li>"
			  	 }else if(obj.status=="2" || obj.status=="11" || obj.status=="12" || obj.status=="10"){
			  		 html+="<li class='spicailItemgreen'>"+obj.publishOrg+"</li>"
			  	 }
				html+="</ul></div>"
			  	 if(obj.flight!=null && obj.flight!="[]" && obj.flight.length!=0){
			  		html+="<div class='col-12'><div class='width60px c-999 mt-10 f-l'>关联航班</div><ul class='f-l spicailItemResouse_1'>" ;
			  		$.each(obj.flight,function(i,n){
			  			html+="<li class='spicailItemGray'>"+n+"</li>"
			  		})
			  		html+="</ul></div>"
			  	 }
		  		 if(obj.receiveList!=null && obj.receiveList!="[]" && obj.receiveList.length!=0){
			  		html+="<div class='col-12'><div class='width60px c-999 f-l mt-10'>关联信息</div><ul class='f-l spicailItemResouse_1'>" ;
			  		$.each(obj.receiveList,function(i,n){
			  			var receiveData=n.type=="2"?n.receiveId:n.receiveOrg;
			  			if(n.flag=="0"){
			  				html+="<li class='spicailItemred'>"+receiveData+"</li>"
			  			}else if(n.flag=="1"){
			  				html+="<li class='spicailItemYellow'>"+receiveData+"</li>"
			  			}else if(n.flag=="2" || n.flag=="11" || n.flag=="10" || n.flag=="12"){
			  				html+="<li class='spicailItemgreen'>"+receiveData+"</li>"
			  			}
			  	 	})
			  	 	html+="</ul></div>"
			  	 } 
			  	 html+="</div>";
				$("#specialReveiveInfo").html(html);
				getRecordId=obj.recordId;
				getSsid=obj.ssid;
				getForward=obj.forword;
				if(obj.flowList!=null && obj.flowList!="[]" && obj.flowList.length!=0){
					$("#specialProcessHtml").show();
					$.each(obj.flowList,function(i,n){
						$('#specialReceiveInfo').append("<li class='col-12 label-green'><div class='col-12 c-999 mt-10'>"+n.senderOrg+"-"+n.name+"&nbsp;&nbsp;&nbsp;"+getTime(n.senderTime)+"</div><div class='col-12'>"+n.forwardContent+"</div></li>")
					})
				}
				if(obj.forword=="1"){
					specialReceive();
					$("#specialReceiveHtml").show();
					$(".specialReveiveLine:eq(1)").hide();
				}else if(obj.forword=="2"){
					$("#specialReplyHtml").show();
					$("#specialForwardHtml").show();
				}else if(obj.forword=="3"){
					specialDispose();
					$("#specialReplyHtml").show();
					$("#specialDisposeHtml").show();
				}else if(obj.forword=="4"){
					if(obj.replyList.length!=0){
						$("#specialReplyHtml").show();
					}else{
						$(".specialReveiveLine:eq(1)").hide();
					}
					$(".specialReveiveLine:eq(2)").hide();
					$("#specialTemDataSave").hide();
					
				}
				if(obj.replyList!=null && obj.replyList!="[]" && obj.replyList.length!=0){
					var html="";
					$.each(obj.replyList,function(i,n){
						if(n.status=="0"){
							if(n.name==null){
								html+="<li class='col-12 label-red'><div class='col-12 mt-10 c-999'>"+specialOrgName(n.orgName)+"&nbsp;未处理</div></li>";
							}else html+="<li class='col-12 label-red'><div class='col-12 mt-10 c-999'>"+specialOrgName(n.orgName)+"-"+n.name+"&nbsp;未处理</div></li>";
							
							/*if(n.receiveType=="0"){
								html+=n.receiveId;
							}else if(n.receiveType=="1"){
								html+=n.receiveOrg;
							}else if(n.receiveType=="2"){
								html+=n.receiveId;
							}*/
							//html+="未处理</div>";
						}else if(n.status=="1"){
							if(n.name==null){
								html+="<li class='col-12 label-yellow'><div class='col-12 mt-10 c-999'>"+specialOrgName(n.orgName);
							}else html+="<li class='col-12 label-yellow'><div class='col-12 mt-10 c-999'>"+specialOrgName(n.orgName)+"-"+n.name;
							
							/*if(n.receiveType=="0"){
								html+=n.receiveId;
							}else if(n.receiveType=="1"){
								html+=n.receiveOrg;
							}else if(n.receiveType=="2"){
								html+=n.receiveId;
							}*/
							if(n.replyContent!=null){
								html+="&nbsp;已回执&nbsp;&nbsp;"+getTime(n.createTime)+"</div><div class='col-12'>"+n.replyContent+"</div></li>";
							}else html+="&nbsp;已回执&nbsp;&nbsp;"+getTime(n.createTime)+"</div></li>";
							
						}else if(n.status=="2" || n.status=="10"){
							if(n.name==null){
								html+="<li class='col-12 label-green'><div class='col-12 mt-10 c-999'>"+specialOrgName(n.orgName);
							}else html+="<li class='col-12 label-green'><div class='col-12 mt-10 c-999'>"+specialOrgName(n.orgName)+"-"+n.name;
							
							/*if(n.receiveType=="0"){
								html+=n.receiveId;
							}else if(n.receiveType=="1"){
								html+=n.receiveOrg;
							}else if(n.receiveType=="2"){
								html+=n.receiveId
								;
							}*/
							if(n.replyContent!=null){
								html+="&nbsp;已回复&nbsp;&nbsp;"+getTime(n.createTime)+"</div><div class='col-12'>"+n.replyContent+"</div></li>";
							}else html+="&nbsp;已回复&nbsp;&nbsp;"+getTime(n.createTime)+"</div></li>";
							
						}else if(n.status=="11"){
							if(n.name==null){
								html+="<li class='col-12 label-green'><div class='col-12 mt-10 c-999'>"+specialOrgName(n.orgName)+"&nbsp;已被撤消</div></li>";
							}else html+="<li class='col-12 label-green'><div class='col-12 mt-10 c-999'>"+specialOrgName(n.orgName)+"-"+n.name+"&nbsp;已被撤消</div></li>";
							
						}else if(n.status=="12"){
							if(n.name==null){
								html+="<li class='col-12 label-green'><div class='col-12 mt-10 c-999'>"+specialOrgName(n.orgName)+"&nbsp;已被强制结束</div></li>";
							}else html+="<li class='col-12 label-green'><div class='col-12 mt-10 c-999'>"+specialOrgName(n.orgName)+"-"+n.name+"&nbsp;已被强制结束</div></li>";
							
						}
					})
					$('#specialReplyInfo').html(html);
				}else $("#specialReplyHtml").hide();
				
			}
		}
	})
	}	
	specialReceiveInfo();
	
	function specialOrgName(obj){
		return obj==null?"":obj;
	}
	//保存数据
	$('#specialTemDataSave').on('click',function(){
		if(getForward=="1"){
			specialReceiveData();
		}else if(getForward=="2"){
			specialForwardData();
		}else if(getForward=="3"){
			specialDisposeData();
		}else if(getForward=="4"){
			
		}

	})

//完成特情---4	
	
//转发特情---3	
var specialDispose=function(){
	var selectItem,selectUrl,selectLocationUrl,templetData,specialDisposeCon;
	$('#specialDisposeHtml').find("input.specialReceiveSelect").on('click',function(e){
		$(e.target).attr('checked','checked')
		$(e.target).siblings().removeAttr('checked')
		$.each($('#specialDisposeHtml').find("div.specialReceiveSelectCon"),function(i,n){
			if($(e.target).attr('data-flag')==i){
				$('#specialDisposeHtml').find("div.specialReceiveSelectCon:eq("+$(e.target).attr('data-flag')+")").show();
			}else {
				$('#specialDisposeHtml').find("div.specialReceiveSelectCon:eq("+i+")").hide();
			}
		})
	})
}	
var specialDisposeData=function(){
	var checkedItem=$('#specialDisposeHtml').find('.specialReceiveSelect:checked');
	selectUrl='/api/special/modifySpecialSituation';
	selectLocationUrl="/api/special/page";
	if(checkedItem.attr('data-flag')=="0"){
		selectItem="撤销";
		specialDisposeCon=$('.specialDisposeContent:eq(0)').val();
		if(specialDisposeCon==""){
			layer.msg("请输入撤销原因！")
			return;
		}
		if(getByteLen(specialDisposeCon)>1024){
			layer.msg("撤销原因内容字数过多");
			return;
		}
		templetData={"status":"11","ssid":getSsid,"content":specialDisposeCon};
	}else {
		selectItem="强制结束";
		specialDisposeCon=$('.specialDisposeContent:eq(1)').val();
		if(specialDisposeCon==""){
			layer.msg("请输入强制结束原因！")
			return;
		}
		if(getByteLen(specialDisposeCon)>1024){
			layer.msg("强制结束原因内容字数过多");
			return;
		}
		templetData={"status":"12","ssid":getSsid,"content":specialDisposeCon};
	}
layer.confirm("您确认"+selectItem+"？",function(index){
	layer.close(index);
	var loadIndex=layer.load("数据正在努力提交中，请稍等!");
	$.ajax({
		type:'POST',
		url:baseURL+selectUrl,
		dataType:'json',
		contentType:"application/json",
		data:JSON.stringify(templetData),
		success:function(result){
			layer.close(loadIndex);
			if(!result.flag){
				layer.msg("数据错误:"+result.message)
			}else{
				layer.msg('提交成功',1,1);
				$("#specialAddForm").find("input,textarea,select").val("");
				window.location.href=baseURL+selectLocationUrl+"?ouath_token="+localStorage.getItem("oauth_token");
			}
		}
	})
})
}	
//处理特情---2	
var specialForwardData=function(){
		if($("#specialForwardContent").val()==""){
			layer.msg("请输入回复原因！")
			return;
		}
		if(getByteLen($("#specialForwardContent").val())>1024){
			layer.msg("回复原因内容字数过多");
			return;
		}
		var templetData={"recordId":getRecordId,"status":2,"content":$("#specialForwardContent").val()}
		selectLocationUrl="/api/special/page";
		layer.confirm("您确认提交？",function(index){
			layer.close(index);
			var loadIndex=layer.load("数据正在努力提交中，请稍等!");
			$.ajax({
				type:'POST',
				url:baseURL+"/api/special/reply",
				dataType:'json',
				contentType:"application/json",
				data:JSON.stringify(templetData),
				success:function(result){
					layer.close(loadIndex);
					if(!result.flag){
						layer.msg("数据错误:"+result.message)
					}else{
						layer.msg('提交成功',1,1);
						$("#specialAddForm").find("input,textarea,select").val("");
						window.location.href=baseURL+selectLocationUrl+"?ouath_token="+localStorage.getItem("oauth_token");
					}
				}
			})
		})
}
//接收特情---1
var specialReceiveData=function(){
		var checkedItem=$('#specialReceiveHtml').find(".specialReceiveSelect:checked");
		if(checkedItem.attr('data-flag')=="0"){
			selectItem="转发";
			selectUrl='/api/special/forward';
			selectLocationUrl="/api/special/page";
			var specialPartSelectedItem=$('#specialPartSelectedItem').find('li');
			var specialPresentSelectedItem=$('#specialPresentSelectedItem').find('li');
			var specialDepartInput=$("#specialDepart").val();
			var specialPresentInput=$("#specialPresent").val();
			if(specialPartSelectedItem.length==0 && specialPresentSelectedItem.length==0){
				layer.msg('请关联部门或抄送人员');
				return;
			}
			if(specialDepartInput=="" && specialPresentInput==""){
				layer.msg('请确定选择好的关联部门或抄送人员');
				return;
			}
			if($("#specialReceiveContent").val()==""){
				layer.msg("请输入内容！");
				return;
			}
			if(getByteLen($("#specialReceiveContent").val())>1024){
				layer.msg("回复原因内容字数过多");
				return;
			}
			var itemDeptList=[];
			var itemUserList=[];
			$.each(specialPartSelectedItem,function(i,n){
				itemDeptList.push({"id":null,"templateId":null,"subCode":$(n).attr('id'),"subName":$(n).text(),"subType":"1"});
				//itemDeptList.push({"id":null,"templateId":null,"roleCode":$(n).attr('roleCode'),"subCode":$(n).attr('subCode'),"subName2":$(n).text().substring(0,$(n).text().length-1),"subName":$(n).attr('subName'),"subCode2":$(n).attr('roleCode'),"subType":"1"});
			})
			if(specialPresentSelectedItem.length!=0 && specialPresentInput!=""){
				$.each(specialPresentSelectedItem,function(i,n){
					itemUserList.push({"id":null,"templateId":null,"subCode":$(n).attr('id'),"subName":$(n).text(),"subType":"2"});
				})
			}
			templetData={"ssid":getSsid,"recordId":getRecordId,"content":$("#specialReceiveContent").val(),"itemDeptList":itemDeptList,"itemUserList":itemUserList};
		}else {
			selectItem="回复";
			selectUrl='/api/special/reply';
			selectLocationUrl="/api/special/page"
			if($("#specialReplyContent").val()==""){
				layer.msg("请输入回复内容！");
				return;
			}
			if(getByteLen($("#specialReplyContent").val())>1024){
				layer.msg("回复原因内容字数过多");
				return;
			}
			templetData={"recordId":getRecordId,"status":2,"content":$('#specialReplyContent').val()};
		}
	layer.confirm("您确认"+selectItem+"？",function(index){
		layer.close(index);
		var loadIndex=layer.load("数据正在努力提交中，请稍等!");
		$.ajax({
			type:'POST',
			url:baseURL+selectUrl,
			dataType:'json',
			contentType:"application/json",
			data:JSON.stringify(templetData),
			success:function(result){
				layer.close(loadIndex);
				if(!result.flag){
					layer.msg("数据错误:"+result.message)
				}else{
					layer.msg('提交成功',1,1);
					$("#specialAddForm").find("input,textarea,select").val("");
					window.location.href=baseURL+selectLocationUrl+"?ouath_token="+localStorage.getItem("oauth_token");
				}
			}
		})
	})	
}	
var specialReceive=function(){
	var selectItem,selectUrl,selectLocationUrl,templetData;
	$('.specialReceiveSelect').on('click',function(e){
		$.each($(".specialReceiveSelectCon"),function(i,n){
			if($(e.target).attr('data-flag')==i){
				$(".specialReceiveSelectCon:eq("+$(e.target).attr('data-flag')+")").show();
			}else $(".specialReceiveSelectCon:eq("+i+")").hide();
		})
	});
	
	var specialAddPart=function(){$.ajax({//部门
		type:'GET',
		url:baseURL+'/services/dept/listSSRDept',
		dataType:'json',
		success:function(result){
			if(result.errorcode=="1"){
        		  layer.msg("查询失败！");
        		  return;
			}
			if(result.errorcode=="0"){
				if(result.results==null){
					layer.msg('没有数据')
					return false;
				}
			var htmlPart="";
			var obj=result.results;
			function returnBack(obj){
				if(!obj) return;
				$.each(obj,function(i,n){
						if(this.subDepartmentList!=null && this.subDepartmentList!="[]" && this.subDepartmentList.length!=0){
							if(this.includeRole){
								htmlPart+="<li><span class='folder' id='"+this.id+"' code='"+this.code+"'>"+this.name+"</span><ul>";
							}else htmlPart+="<li><span class='folder disabled c-999' id='"+this.id+"' code='"+this.code+"'>"+this.name+"</span><ul>";
							returnBack(this.subDepartmentList)
							htmlPart+="</ul>";
						}else {
							if(this.includeRole){
								htmlPart+="<li><span class='file' id='"+this.id+"' code='"+this.code+"'>"+this.name+"</span>";	
							}else htmlPart+="<li><span class='file disabled c-999' id='"+this.id+"' code='"+this.code+"'>"+this.name+"</span>";	
						}
				})
				htmlPart+="</li>";
			}
			returnBack(obj)
			$('#specialPartItem').html(htmlPart)
			$('#specialPartItem').find('span:not(.disabled)').on('click',function(e){
				e.stopPropagation();
				$('#specialPartItem').find('span').removeClass('commonSelectBK')
				$(e.target).addClass('commonSelectBK');
				partSelectId=$(e.target).attr('id');
				partSelectText=$(e.target).text();
			})
			$('#specialPartSelectedItemAddBtn').on('click',function(e){
				e.stopPropagation()
				if(partSelectId=="" && partSelectText==""){
					layer.msg("请选择部门！")
					return false;
				}
				var specialPartSelectedItem=$('#specialPartSelectedItem').find('li');
				var flag=true;
				if(specialPartSelectedItem.length!=0){
					$.each(specialPartSelectedItem,function(i,n){
						if($(n).attr('id')==partSelectId){
							layer.msg('请不要重复添加')
							flag=false;
						}
					})
					if(flag){
						$('#specialPartSelectedItem').append("<li id='"+partSelectId+"' onclick=\"changePortSelect(this)\">"+partSelectText+"</li>");
					}
				}else {
					$('#specialPartSelectedItem').append("<li id='"+partSelectId+"' onclick=\"changePortSelect(this)\">"+partSelectText+"</li>");
				}
			})
			$("#specialPartSelectedItemShowBtn").on('click',function(e){
				$(e.target).parents("div.specialSelect").hide();
				var inputPartHtml="";
				$.each($('#specialPartSelectedItem').find('li'),function(i,n){
					inputPartHtml+=$(n).text()+",";
				})
				$("#specialDepart").val(specialSubString(inputPartHtml))
				$("#specialPresentSelectedAllItem").find('li').removeClass("airportSelectBK");
			})
			$('#specialPartSelectedItemRemoveBtn').on('click',function(e){
					var inputPartHtml="";
					e.stopPropagation();
					var specialPartRemoveItem=$('#specialPartSelectedItem').find('li.airportSelectBK');
					if(specialPartRemoveItem.length==0){
						return false;
					}
					if(specialPartRemoveItem.length!=0){
						$.each(specialPartRemoveItem,function(i,n){
							$(n).remove();
						})
					}
					$.each($('#specialPartSelectedItem').find('li'),function(i,n){
						inputPartHtml+=$(n).text()+",";
					})
					$("#specialDepart").val(specialSubString(inputPartHtml))
			})
			$("#specialPartSelectedItemHiddenBtn").on('click',function(){
				$("#specialDepart").val("")
				$('#specialPartSelectedItem').empty();
			})
			$("#specialPartItem").treeview({
				animated: "fast",
				collapsed: true,
				unique: true,
				//persist: "cookie",
				toggle: function() {
					//window.console && console.log("%o was toggled", this);
				}
			})
		}
		},
		error:function(e){
			layer.msg(e)
		}
	})
	}
	specialAddPart();
	//抄送人员
	var specialAddPresent=function(){$.ajax({
		type:'GET',
		url:baseURL+'/services/dept/listDept',
		dataType:'json',
		success:function(result){
			if(result.errorcode=="1"){
        		  layer.msg("查询失败！");
        		  return;
			}
			if(result.errorcode=="0"){
				if(result.results==null){
					layer.msg('没有数据')
					return false;
				}
			var htmlPart="";
			var obj=result.results;
			function returnBack(obj){
				if(!obj) return;
				$.each(obj,function(){
						if(this.subDepartmentList!=null && this.subDepartmentList!="[]" && this.subDepartmentList.length!=0){
							htmlPart+="<li><span class='folder' id='"+this.id+"' code='"+this.code+"'>"+this.name+"</span><ul>";
							returnBack(this.subDepartmentList)
							htmlPart+="</ul>";
						}else {
							htmlPart+="<li><span class='file' id='"+this.id+"' code='"+this.code+"'>"+this.name+"</span>";	
						}
				})
				htmlPart+="</li>";
			}
			returnBack(obj)
			$('#specialPresentItem').html(htmlPart)
			$('#specialPresentItem').find('span').on('click',function(e){
				e.stopPropagation();
				$('#specialPresentItem').find('span').removeClass('commonSelectBK')
				$(e.target).addClass('commonSelectBK')
				$('#specialPresentSelectedAllItem').empty();
				specialPresent($(e.target).attr('id'));
			})
			$("#specialPresentSelectedItemShowBtn").on('click',function(e){
				$(e.target).parents("div.specialSelect").hide();
				var inputPresentHtml="";
				if($('#specialPresentSelectedItem').find('li').length!=0){
					$.each($('#specialPresentSelectedItem').find('li'),function(i,n){
						inputPresentHtml+=$(n).text()+",";
					})
					$("#specialPresent").val(specialSubString(inputPresentHtml))
				}else $("#specialPresent").val("");
			})
			$('#specialPresentSelectedItemAddBtn').on('click',function(e){
					e.stopPropagation()
					var specialPresentSelectedItem=$('#specialPresentSelectedItem').find('li');
					var specialPresentSelectedAllItem=$('#specialPresentSelectedAllItem').find('li.airportSelectBK');
					if(specialPresentSelectedAllItem.length==0){
						layer.msg("请选择人员！")
						return false;
					}
					var flag=true;
					if(specialPresentSelectedItem.length!=0){
						$.each(specialPresentSelectedAllItem,function(i,n){
							$.each(specialPresentSelectedItem,function(o,p){
								if($(n).attr('id')==$(p).attr('id')){
									layer.msg('请不要重复添加');
									flag=false;
								}
							})
						})
						if(flag){
							$.each(specialPresentSelectedAllItem,function(i,n){
								$('#specialPresentSelectedItem').append("<li id='"+$(n).attr('id')+"' onclick=\"changePortSelect(this)\">"+$(n).text()+"</li>");
							})
						}
					}else {
						$.each(specialPresentSelectedAllItem,function(i,n){
							$('#specialPresentSelectedItem').append("<li id='"+$(n).attr('id')+"' onclick=\"changePortSelect(this)\">"+$(n).text()+"</li>");
						})
					}
			})
			$("#specialPresentItem").treeview({
				animated: "fast",
				collapsed: true,
				unique: true,
				//persist: "cookie",
				toggle: function() {
					//window.console && console.log("%o was toggled", this);
				}
			})
		}
		},
		error:function(e){
			layer.msg(e)
		}
	})
	}
	specialAddPresent();
	
	//相关人员
	var specialPresent=function(id){
		$.ajax({    
		type:'GET',
		url:baseURL+'/services/dept/listEmployee/'+id,
		dataType:'json',
		contentType:"application/json",
		success:function(result){
			if(result.errorcode=="1"){
          		  layer.msg("查询失败！");
          		  return false;
			}
			if(result.errorcode=="0"){
				if(result.results==null){
					layer.msg('没有数据')
					return false;
				}
				var html="";
				var inputPresentHtml,inputPresentHtml_1;
				if(result.results!=null && result.results.length!=0 && result.results!="[]"){
					$.each(result.results,function(i,n){
						html+="<li id='"+n.id+"' onclick=\"changePortSelect(this)\">"+n.empName+"</li>"
					})
					$('#specialPresentSelectedAllItem').html(html);
				}else $('#specialPresentSelectedAllItem').html("<div class='text-c mt-20'>无数据</div>");
				$('#specialPresentSelectedItemRemoveBtn').on('click',function(e){
						var inputPresentHtml="";
						e.stopPropagation();
						var specialPartRemoveItem=$('#specialPresentSelectedItem').find('li.airportSelectBK');
						var specialPartRemoveAllItem=$('#specialPresentSelectedAllItem').find('li');
						$.each(specialPartRemoveAllItem,function(i,n){
							$.each(specialPartRemoveItem,function(o,p){
								if($(n).attr('id')==$(p).attr('id')){
									$(n).removeClass("airportSelectBK");
								}
							})
						})
						if(specialPartRemoveItem.length==0){
							return false;
						}
						if(specialPartRemoveItem.length!=0){
							$.each(specialPartRemoveItem,function(i,n){
								$(n).remove();
							})
						}
				})
				$("#specialPresentSelectedItemHiddenBtn").on('click',function(){
					$("#specialPresent").val("")
					$('#specialPresentSelectedItem').empty();
					$('#specialPresentSelectedAllItem').find('li').removeClass("airportSelectBK");
				})
			}
		},
		error:function(e){
			layer.msg(e)
		}
	})
}
	
	/*specialAddPart=function(){$.ajax({//部门
		type:'GET',
		url:baseURL+'/services/dept/listSSRDept',
		dataType:'json',
		success:function(result){
			if(result.errorcode=="1"){
        		  layer.msg("查询失败！");
        		  return;
			}
			if(result.errorcode=="0"){
				if(result.results==null){
					layer.msg('没有数据')
					return false;
				}
			var htmlPart="";
			var obj=result.results;
			function returnBack(obj){
				if(!obj) return;
				$.each(obj,function(i,n){
						if(this.subDepartmentList!=null && this.subDepartmentList!="[]" && this.subDepartmentList.length!=0){
							if(this.includeRole){
								htmlPart+="<li><span class='folder' id='"+this.id+"' code='"+this.code+"'>"+this.name+"</span><ul>";
							}else htmlPart+="<li><span class='folder disabled c-999' id='"+this.id+"' code='"+this.code+"'>"+this.name+"</span><ul>";
							returnBack(this.subDepartmentList)
							htmlPart+="</ul>";
						}else {
							if(this.includeRole){
								htmlPart+="<li><span class='file' id='"+this.id+"' code='"+this.code+"'>"+this.name+"</span>";	
							}else htmlPart+="<li><span class='file disabled c-999' id='"+this.id+"' code='"+this.code+"'>"+this.name+"</span>";	
						}
				})
				htmlPart+="</li>";
			}
			returnBack(obj)
			$('#specialPartItem').append(htmlPart)
			$('#specialPresentItem').append(htmlPart)
			$('#specialPartItem').find('span').on('click',function(e){
				e.stopPropagation();
				$('#specialPartItem').find('span').removeClass('commonSelectBK')
				$(e.target).addClass('commonSelectBK')
				$('#specialPartSelectedAllItem').empty();
				specialPart($(e.target).attr('id'),$(e.target).text());
			})
			//人员
			$('#specialPresentItem').find('span').on('click',function(e){
				e.stopPropagation();
				$('#specialPresentItem').find('span').removeClass('commonSelectBK')
				$(e.target).addClass('commonSelectBK')
				$('#specialPresentSelectedAllItem').empty();
				specialPresent($(e.target).attr('id'));
			})
			$("#specialPartItem,#specialPresentItem").treeview({
				animated: "fast",
				collapsed: true,
				unique: true,
				//persist: "cookie",
				toggle: function() {
					//window.console && console.log("%o was toggled", this);
				}
			})
		}
		},
		error:function(e){
			layer.msg(e)
		}
	})
	}
	specialAddPart();
	//相关角色
	var specialPart=function(id,partName){
		$.ajax({    
		type:'GET',
		url:baseURL+'/services/dept/listRole/'+id,
		dataType:'json',
		contentType:"application/json",
		success:function(result){
			if(result.errorcode=="1"){
          		  layer.msg("查询失败！");
          		  return false;
			}
			if(result.errorcode=="0"){
				if(result.results==null){
					layer.msg('没有数据')
					return false;
				}
				var html="";
				var inputPartHtml_1,inputPartHtml;
				if(result.results!=null && result.results.length!=0 && result.results!="[]"){
					$.each(result.results,function(i,n){
						html+="<li roleCode='"+n.code+"'>"+n.name+"<span class='ml-5 c-red'>("+partName+")</span>"+"</li>"
					})
					$('#specialPartSelectedAllItem').html(html);
				}else $('#specialPartSelectedAllItem').html("<div class='text-c mt-20'>无数据</div>");
				$('#specialPartSelectedAllItem').find('li').on('click',function(e){
					inputPartHtml="";
					e.stopPropagation();
					$(e.target).toggleClass("commonSelectColor");
					var specialPartSelectedItem=$('#specialPartSelectedAllItem').next().find('li');
					var flag=true;
					if(specialPartSelectedItem.length!=0){
						$.each(specialPartSelectedItem,function(i,n){
							if($(n).attr('roleCode')==$(e.currentTarget).attr('roleCode')){
								layer.msg('请不要重复添加')
								flag=false;
							}
						})
						if(flag){
							$('#specialPartSelectedAllItem').next().append("<li subCode='"+id+"' subName='"+partName+"' roleCode ='"+$(e.currentTarget).attr('roleCode')+"'>"+$(e.currentTarget).html()+"<span class='f-r mr-10 iconDelete'>x</span></li>");
						}
					}else {
						$('#specialPartSelectedAllItem').next().append("<li subCode='"+id+"' subName='"+partName+"' roleCode='"+$(e.currentTarget).attr('roleCode')+"'>"+$(e.currentTarget).html()+"<span class='f-r mr-10 iconDelete'>x</span></li>");
					}
					$.each($('#specialPartSelectedItem').find('li'),function(i,n){
						inputPartHtml+=specialSubString($(n).text())+",";
					})
					$("#specialDepart").val(specialSubString(inputPartHtml))
					$('.iconDelete').on('click',function(ev){
						ev.stopPropagation();
						inputPartHtml_1="";
						$(ev.target).parent().remove();
						$.each($("#specialPartSelectedItem").find('li'),function(i,n){
							inputPartHtml_1+=specialSubString($(n).text())+",";
						})
						$("#specialDepart").val(specialSubString(inputPartHtml_1));
					})
				})
			}
		},
		error:function(e){
			layer.msg(e)
		}
	})
}
	//相关人员
	var specialPresent=function(id){
		$.ajax({    
		type:'GET',
		url:baseURL+'/services/dept/listEmployee/'+id,
		dataType:'json',
		contentType:"application/json",
		success:function(result){
			if(result.errorcode=="1"){
          		  layer.msg("查询失败！");
          		  return false;
			}
			if(result.errorcode=="0"){
				if(result.results==null){
					layer.msg('没有数据')
					return false;
				}
				var html="";
				var inputPresentHtml,inputPresentHtml_1;
				if(result.results!=null && result.results.length!=0 && result.results!="[]"){
					$.each(result.results,function(i,n){
						html+="<li id='"+n.id+"'>"+n.empName+"</li>"
					})
					$('#specialPresentSelectedAllItem').html(html);
				}else $('#specialPresentSelectedAllItem').html("<div class='text-c mt-20'>无数据</div>");
				$('#specialPresentSelectedAllItem').find('li').on('click',function(e){
					e.stopPropagation();
					$(e.target).toggleClass("commonSelectColor");
					inputPresentHtml="";
					var specialPartSelectedItem=$('#specialPresentSelectedAllItem').next().find('li');
					var flag=true;
					if(specialPartSelectedItem.length!=0){
						$.each(specialPartSelectedItem,function(i,n){
							if($(n).attr('id')==$(e.currentTarget).attr('id')){
								layer.msg('请不要重复添加')
								flag=false;
							}
						})
						if(flag){
							$('#specialPresentSelectedAllItem').next().append("<li id='"+$(e.currentTarget).attr('id')+"'>"+$(e.currentTarget).text()+"<span class='f-r mr-10 iconDelete'>x</span></li>");
						}
					}else {
						$('#specialPresentSelectedAllItem').next().append("<li id='"+$(e.currentTarget).attr('id')+"'>"+$(e.currentTarget).text()+"<span class='f-r mr-10 iconDelete'>x</span></li>");
					}
					$.each($("#specialPresentSelectedItem").find('li'),function(i,n){
						inputPresentHtml+=$(n).text().substring(0,$(n).text().length-1)+",";
					})
					$("#specialPresent").val(specialSubString(inputPresentHtml))
					$('.iconDelete').on('click',function(ev){
						ev.stopPropagation();
						inputPresentHtml_1="";
						$(ev.target).parent().remove();
						$.each($("#specialPresentSelectedItem").find('li'),function(i,n){
							inputPresentHtml_1+=$(n).text().substring(0,$(n).text().length-1)+",";
						})
						$("#specialPresent").val(specialSubString(inputPresentHtml_1));
					})
				})
			}
		},
		error:function(e){
			layer.msg(e)
		}
	})
}*/
	
	
	//模板选择下拉菜单
	/*$('.specialDropDown').find('button').on('click',function(){
		$('.specialDropDown').find('ul').toggle();
	})
	$('.specialOpenTempList').on('click',function(){
		window.location.href=baseURL+"/api/special/template/page/list?ouath_token="+localStorage.getItem("oauth_token");
	})
	$('.specialClose').on('click',function(e){
		$(e.target).parents('ul').toggle();
	})
	$.ajax({   //按钮选择模板
		type:'GET',
		url:baseURL+'/api/special/template/list',
		dataType:'json',
		success:function(result){
			if(!result.flag){
				layer.msg('数据出错:'+result.message)
			}else{
				$.each(result.results,function(i,n){
					$('.specialDropDownMenu').append("<li id='"+n.id+"'>"+n.topic+"</li>")
				})
				$('.specialDropDownMenu').find('li:not(:first)').on('click',function(e){
					e.stopPropagation();
					layer.confirm("您确定运用特情模板："+$(e.target).text(),function(){
						specialTempShow($(e.target).attr('id'));
						layer.msg("成功运用",1,1);
						$('.specialClose').trigger('click');
						$("#specialPartSelectedItem").empty();
						$("#specialPresentSelectedItem").empty();
						$("#specialDepart").empty();
						$("#specialPresent").empty();
					})
				})
			}
		},
		error:function(e){
			layer.msg(e)
		}
	})
	var specialTempShow=function(specialTemId){
	//初始化数据
	$.ajax({
		type:'GET',
		url:baseURL+'/api/special/template/get/'+specialTemId,
		dataType:'json',
		success:function(result){
			if(!result.flag){
				layer.msg("错误："+result.message);
			}
			if(result.flag){
				var results=result.result;
				specialTemId=results.id;
				if(results.itemDeptList!=null){
					var specialPartTempHtml="";
					$.each(results.itemDeptList,function(i,n){
						$("#specialPartSelectedItem").append("<li subCode='"+n.subCode+"' subCode2='"+n.subCode2+"' roleCode='"+n.roleCode+"' >"+n.subName2+"<span class='f-r mr-10 iconDelete'>x</span></li>")
						specialPartTempHtml+=n.subName2+",";
					})
					$("#specialDepart").val(specialPartTempHtml.substring(0,specialPartTempHtml.length-1));
					$('.iconDelete').on('click',function(ev){
						ev.stopPropagation();
						var inputPartHtml_1="";
						$(ev.target).parent().remove();
						$.each($("#specialPartSelectedItem").find('li'),function(i,n){
							inputPartHtml_1+=specialSubString($(n).text())+",";
						})
						$("#specialDepart").val(specialSubString(inputPartHtml_1));
					})
				}
				if(results.itemUserList!=null){
					var specialPresentTempHtml="";
					$.each(results.itemUserList,function(i,n){
						$("#specialPresentSelectedItem").append("<li id='"+n.subCode+"'>"+n.subName+"<span class='f-r mr-10 iconDelete'>x</span></li>")
						specialPresentTempHtml+=n.subName+",";
					})
					$("#specialPresent").val(specialPresentTempHtml.substring(0,specialPresentTempHtml.length-1));
					$('.iconDelete').on('click',function(ev){
						ev.stopPropagation();
						var inputPresentHtml_1="";
						$(ev.target).parent().remove();
						$.each($("#specialPresentSelectedItem").find('li'),function(i,n){
							inputPresentHtml_1+=$(n).text().substring(0,$(n).text().length-1)+",";
						})
						$("#specialPresent").val(specialSubString(inputPresentHtml_1));
					})
				}
			}
			
		},
		error:function(e){
			layer.msg(e)
		}
	})
	}*/
}

var isMouse=true;
$('.specialSelectInput').on('click',function(e){
	e.stopPropagation();
	$(e.target).attr('flag','false')
	$.each($('.specialSelectInput'),function(i,n){
		if($(n).attr('flag')=="true"){
			$(n).next().hide();
		}else $(n).attr('flag','true')
	})
	$(e.target).next().toggle();
	$(e.target).next().on('mouseleave',function(ev){
		ev.stopPropagation();
		$(e.target).next().hide();
		isMouse=true;
	})
	$(e.target).next().on('mouseover',function(ev){
		isMouse=false;
	})
})
$('.specialSelectInput').on('blur',function(e){
	if(isMouse){
		$(e.target).next().hide();
	}
})

function specialSubString(args){
	return args.substring(0,args.length-1);
}



function getTime(t){
	 var date=new Date(t);
	 return date.getFullYear()+"-"+changeTime((date.getMonth()+1))+"-"+changeTime(date.getDate())+"&nbsp;"+changeTime(date.getHours())+":"+changeTime(date.getMinutes());
}
function changeTime(obj){
	return obj<10?"0"+obj:obj;
}
	
//定时刷新
var specicalReveiveRefever
$("#specialRerfever").on('click',function(){
	if($("#specialRerfever").is(":checked")){
		specicalReveiveRefever=setInterval(function(){
			var specialAddForm=$("#specialAddForm");
			specialAddForm.find("ul").empty();
			specialAddForm.find('input,textarea').val("");
			partSelectId="";
			partSelectText="";
			$('#specialPartSelectedItemAddBtn,#specialPresentSelectedItemAddBtn').off("click");
			specialReceiveInfo();
			//window.location.reload();
		},90000)
	}else clearInterval(specicalReveiveRefever);
})
/*specicalReveiveRefever=setInterval(function(){
			$("#specialReceiveInfo").empty();
			$("#specialReplyInfo").empty();
			//$("#specialPartItem").empty();
			//$("#specialPresentItem").empty();
			//specialReceiveInfo();
			window.location.reload();
		},90000)	*/
})
function changePortSelect(obj){
	$(obj).toggleClass("airportSelectBK");
}
function changeLevelColor(obj){
	if(obj=="T1"){
		return "<span class='specialLevel' style='background:#29c6ef'>"+obj+"</span>"
	}else if(obj=="T2"){
		return "<span class='specialLevel' style='background:#4884c2'>"+obj+"</span>"
	}else if(obj=="T3"){
		return "<span class='specialLevel' style='background:#ffc001'>"+obj+"</span>"
	}else if(obj=="T4"){
		return "<span class='specialLevel' style='background:#ff6600'>"+obj+"</span>"
	}else if(obj=="T5"){
		return "<span class='specialLevel' style='background:#da0001'>"+obj+"</span>"
	}
}
//获取字符串长度（汉字算两个字符，字母数字算一个）
function getByteLen(val) {
  var len = 0;
  for (var i = 0; i < val.length; i++) {
    var a = val.charAt(i);
    if (a.match(/[^\x00-\xff]/ig) != null) {
      len += 2;
    }
    else {
      len += 1;
    }
  }
  return len;
}